#自定义分页器
from api.models import Compture
from django_filters.rest_framework import FilterSet
class Limit:
    def filter_queryset(self,request,queryset,view):
        limit=request.query_params.get("limit")
        if limit:
            limit = int(limit)
            return queryset[:limit]
        print(limit)

        return queryset

#django-filter过滤器
class Compturefilter(FilterSet):
    from django_filters import filters
    min_price=filters.NumberFilter(field_name="price",lookup_expr="gte") #前者指定查询的字段,后者限定范围
    max_price=filters.NumberFilter(field_name="price",lookup_expr="lte")

    class Meta:
        model=Compture
        fields=["brand","min_price","max_price"]

